/*
 * @(#)MtmWfStepNotificationRule.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.workflow.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.ErrorConstant;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.SqlAccountUtility;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.UserInfoFactory;
import com.dcivision.framework.Utility;
import com.dcivision.framework.bean.AbstractBaseObject;
import com.dcivision.framework.dao.AbstractDAObject;
import com.dcivision.framework.web.AbstractSearchForm;
import com.dcivision.workflow.bean.MtmWfStepNotificationRule;
import com.dcivision.workflow.bean.MtmWfStepNotificationTarget;
import com.dcivision.workflow.bean.WorkflowStep;

/**
 * MtmWfStepNotificationRuleDAObject.java
 *
 * This class is the data access bean for table "MTM_WF_STEP_NOTIFY_RULE".
 *
 * @author Dick Xie
 * @company DCIVision Limited
 * @creation date 07/12/2004
 * @version $Revision: 1.8 $
*/

public class MtmWfStepNotificationRuleDAObject extends AbstractDAObject {

  public static final String REVISION = "$Revision: 1.8 $";

  public static final String TABLE_NAME = "MTM_WF_STEP_NOTIFY_RULE";

  public MtmWfStepNotificationRuleDAObject(SessionContainer sessionContainer, Connection dbConn) {
    super(sessionContainer, dbConn);
  }

  protected void initDBSetting() {
    this.baseTableName = TABLE_NAME;
    this.vecDBColumn.add("ID");
    this.vecDBColumn.add("WORKFLOW_STEP_ID");
    this.vecDBColumn.add("NOTIFY_TRIGGER");
    this.vecDBColumn.add("NOTIFY_AT_FIELD");
    this.vecDBColumn.add("NOTIFY_AT_AMT");
    this.vecDBColumn.add("NOTIFY_ACK_METHOD");
    this.vecDBColumn.add("RECORD_STATUS");
    this.vecDBColumn.add("UPDATE_COUNT");
    this.vecDBColumn.add("CREATOR_ID");
    this.vecDBColumn.add("CREATE_DATE");
    this.vecDBColumn.add("UPDATER_ID");
    this.vecDBColumn.add("UPDATE_DATE");
  }

  protected synchronized AbstractBaseObject getByID(Integer id) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.WORKFLOW_STEP_ID, A.NOTIFY_TRIGGER, A.NOTIFY_AT_FIELD, A.NOTIFY_AT_AMT, A.NOTIFY_ACK_METHOD, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   MTM_WF_STEP_NOTIFY_RULE A ");
        sqlStat.append("WHERE  A.ID = ? AND A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, id);
        this.setPrepareStatement(preStat, 2, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        if (rs.next()) {
          MtmWfStepNotificationRule tmpMtmWfStepNotificationRule = new MtmWfStepNotificationRule();
          tmpMtmWfStepNotificationRule.setID(getResultSetInteger(rs, "ID"));
          tmpMtmWfStepNotificationRule.setWorkflowStepID(getResultSetInteger(rs, "WORKFLOW_STEP_ID"));
          tmpMtmWfStepNotificationRule.setNotifyTrigger(getResultSetString(rs, "NOTIFY_TRIGGER"));
          tmpMtmWfStepNotificationRule.setNotifyAtField(getResultSetInteger(rs, "NOTIFY_AT_FIELD"));
          tmpMtmWfStepNotificationRule.setNotifyAtAmt(getResultSetInteger(rs, "NOTIFY_AT_AMT"));
          tmpMtmWfStepNotificationRule.setNotifyAckMethod(getResultSetString(rs, "NOTIFY_ACK_METHOD"));
          tmpMtmWfStepNotificationRule.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpMtmWfStepNotificationRule.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpMtmWfStepNotificationRule.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpMtmWfStepNotificationRule.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpMtmWfStepNotificationRule.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpMtmWfStepNotificationRule.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpMtmWfStepNotificationRule.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWfStepNotificationRule.getCreatorID()));
          tmpMtmWfStepNotificationRule.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWfStepNotificationRule.getUpdaterID()));
          return(tmpMtmWfStepNotificationRule);
        } else {
          throw new ApplicationException(ErrorConstant.DB_RECORD_NOT_FOUND_ERROR);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected synchronized List getList(AbstractSearchForm searchForm) throws ApplicationException {
    PreparedStatement preStat = null;
    PreparedStatement preStatCnt = null;
    ResultSet rs = null;
    ResultSet rsCnt = null;
    StringBuffer sqlStat = new StringBuffer();
    StringBuffer sqlStatCnt = new StringBuffer();
    List result = new ArrayList();
    int totalNumOfRecord = 0;
    int rowLoopCnt = 0;
    int startOffset = TextUtility.parseInteger(searchForm.getCurStartRowNo());
    int pageSize = TextUtility.parseInteger(searchForm.getPageOffset());

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.WORKFLOW_STEP_ID, A.NOTIFY_TRIGGER, A.NOTIFY_AT_FIELD, A.NOTIFY_AT_AMT, A.NOTIFY_ACK_METHOD, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   MTM_WF_STEP_NOTIFY_RULE A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");

        // Form the WHERE clause for filtering.
        if (searchForm.isSearchable()) {
          String searchField = getSearchColumn(searchForm.getBasicSearchField());
          sqlStat.append("AND  " + searchField + " " + searchForm.getBasicSearchType() + " ? ");
        }

        //format the sql for any 'LIKE' statement contained
        sqlStat = this.getFormattedSQL(sqlStat.toString());

        // Form the ORDER clause for sorting.
        if (searchForm.isSortable()) {
          String sortAttribute = searchForm.getSortAttribute();
          if (sortAttribute.indexOf(".") < 0) {
            sortAttribute = "A." + sortAttribute;
          }
          sqlStat.append("ORDER BY " + sortAttribute + " " + searchForm.getSortOrder());
        }

        // Get total number of record return.
        sqlStatCnt = this.getSelectCountSQL(sqlStat);
        preStatCnt = dbConn.prepareStatement(sqlStatCnt.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStatCnt, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStatCnt, 2, searchKeyword);
        }
        rsCnt = preStatCnt.executeQuery();
        if (rsCnt.next()) {
          totalNumOfRecord = rsCnt.getInt(1);
        }
        try { rsCnt.close(); } catch (Exception ignore) {} finally { rsCnt = null; }
        try { preStatCnt.close(); } catch (Exception ignore) {} finally { preStatCnt = null; }

        // Retrieve the result in row basis.
        sqlStat = this.getSelectListSQL(sqlStat, startOffset, pageSize);
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStat, 2, searchKeyword);
        }
        rs = preStat.executeQuery();

        this.positionCursor(rs, startOffset, pageSize);

        while (rs.next() && rowLoopCnt<pageSize) {
          MtmWfStepNotificationRule tmpMtmWfStepNotificationRule = new MtmWfStepNotificationRule();
          tmpMtmWfStepNotificationRule.setID(getResultSetInteger(rs, "ID"));
          tmpMtmWfStepNotificationRule.setWorkflowStepID(getResultSetInteger(rs, "WORKFLOW_STEP_ID"));
          tmpMtmWfStepNotificationRule.setNotifyTrigger(getResultSetString(rs, "NOTIFY_TRIGGER"));
          tmpMtmWfStepNotificationRule.setNotifyAtField(getResultSetInteger(rs, "NOTIFY_AT_FIELD"));
          tmpMtmWfStepNotificationRule.setNotifyAtAmt(getResultSetInteger(rs, "NOTIFY_AT_AMT"));
          tmpMtmWfStepNotificationRule.setNotifyAckMethod(getResultSetString(rs, "NOTIFY_ACK_METHOD"));
          tmpMtmWfStepNotificationRule.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpMtmWfStepNotificationRule.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpMtmWfStepNotificationRule.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpMtmWfStepNotificationRule.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpMtmWfStepNotificationRule.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpMtmWfStepNotificationRule.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpMtmWfStepNotificationRule.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWfStepNotificationRule.getCreatorID()));
          tmpMtmWfStepNotificationRule.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWfStepNotificationRule.getUpdaterID()));
          tmpMtmWfStepNotificationRule.setRecordCount(totalNumOfRecord);
          tmpMtmWfStepNotificationRule.setRowNum(startOffset++);
          ++rowLoopCnt;
          result.add(tmpMtmWfStepNotificationRule);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
        try { rsCnt.close(); } catch (Exception ignore) {} finally { rsCnt = null; }
        try { preStatCnt.close(); } catch (Exception ignore) {} finally { preStatCnt = null; }
      }
    }
  }

  protected synchronized List getList() throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.WORKFLOW_STEP_ID, A.NOTIFY_TRIGGER, A.NOTIFY_AT_FIELD, A.NOTIFY_AT_AMT, A.NOTIFY_ACK_METHOD, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   MTM_WF_STEP_NOTIFY_RULE A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        while (rs.next()) {
          MtmWfStepNotificationRule tmpMtmWfStepNotificationRule = new MtmWfStepNotificationRule();
          tmpMtmWfStepNotificationRule.setID(getResultSetInteger(rs, "ID"));
          tmpMtmWfStepNotificationRule.setWorkflowStepID(getResultSetInteger(rs, "WORKFLOW_STEP_ID"));
          tmpMtmWfStepNotificationRule.setNotifyTrigger(getResultSetString(rs, "NOTIFY_TRIGGER"));
          tmpMtmWfStepNotificationRule.setNotifyAtField(getResultSetInteger(rs, "NOTIFY_AT_FIELD"));
          tmpMtmWfStepNotificationRule.setNotifyAtAmt(getResultSetInteger(rs, "NOTIFY_AT_AMT"));
          tmpMtmWfStepNotificationRule.setNotifyAckMethod(getResultSetString(rs, "NOTIFY_ACK_METHOD"));
          tmpMtmWfStepNotificationRule.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpMtmWfStepNotificationRule.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpMtmWfStepNotificationRule.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpMtmWfStepNotificationRule.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpMtmWfStepNotificationRule.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpMtmWfStepNotificationRule.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpMtmWfStepNotificationRule.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWfStepNotificationRule.getCreatorID()));
          tmpMtmWfStepNotificationRule.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWfStepNotificationRule.getUpdaterID()));
          result.add(tmpMtmWfStepNotificationRule);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
 

  protected void validateInsert(AbstractBaseObject obj) throws ApplicationException {
  }

  protected void validateUpdate(AbstractBaseObject obj) throws ApplicationException {
  }

  protected void validateDelete(AbstractBaseObject obj) throws ApplicationException {
  }

  protected synchronized AbstractBaseObject insert(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    MtmWfStepNotificationRule tmpMtmWfStepNotificationRule = (MtmWfStepNotificationRule)((MtmWfStepNotificationRule)obj).clone();

    synchronized(dbConn) {
      try {
        Integer nextID = getNextPrimaryID();
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("INSERT ");
        sqlStat.append("INTO   MTM_WF_STEP_NOTIFY_RULE(ID, WORKFLOW_STEP_ID, NOTIFY_TRIGGER, NOTIFY_AT_FIELD, NOTIFY_AT_AMT, NOTIFY_ACK_METHOD, RECORD_STATUS, UPDATE_COUNT, CREATOR_ID, CREATE_DATE, UPDATER_ID, UPDATE_DATE) ");
        sqlStat.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, nextID);
        setPrepareStatement(preStat, 2, tmpMtmWfStepNotificationRule.getWorkflowStepID());
        setPrepareStatement(preStat, 3, tmpMtmWfStepNotificationRule.getNotifyTrigger());
        setPrepareStatement(preStat, 4, tmpMtmWfStepNotificationRule.getNotifyAtField());
        setPrepareStatement(preStat, 5, tmpMtmWfStepNotificationRule.getNotifyAtAmt());
        setPrepareStatement(preStat, 6, tmpMtmWfStepNotificationRule.getNotifyAckMethod());
        setPrepareStatement(preStat, 7, GlobalConstant.RECORD_STATUS_ACTIVE);
        setPrepareStatement(preStat, 8, new Integer(0));
        setPrepareStatement(preStat, 9, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 10, currTime);
        setPrepareStatement(preStat, 11, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 12, currTime);
        preStat.executeUpdate();
        tmpMtmWfStepNotificationRule.setID(nextID);
        tmpMtmWfStepNotificationRule.setCreatorID(sessionContainer.getUserRecordID());
        tmpMtmWfStepNotificationRule.setCreateDate(currTime);
        tmpMtmWfStepNotificationRule.setUpdaterID(sessionContainer.getUserRecordID());
        tmpMtmWfStepNotificationRule.setUpdateDate(currTime);
        tmpMtmWfStepNotificationRule.setUpdateCount(new Integer(0));
        tmpMtmWfStepNotificationRule.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWfStepNotificationRule.getCreatorID()));
        tmpMtmWfStepNotificationRule.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWfStepNotificationRule.getUpdaterID()));
        return(tmpMtmWfStepNotificationRule);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_INSERT_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected synchronized AbstractBaseObject update(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    MtmWfStepNotificationRule tmpMtmWfStepNotificationRule = (MtmWfStepNotificationRule)((MtmWfStepNotificationRule)obj).clone();

    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("UPDATE MTM_WF_STEP_NOTIFY_RULE ");
        sqlStat.append("SET  WORKFLOW_STEP_ID=?, NOTIFY_TRIGGER=?, NOTIFY_AT_FIELD=?, NOTIFY_AT_AMT=?, NOTIFY_ACK_METHOD=?, UPDATE_COUNT=?, UPDATER_ID=?, UPDATE_DATE=? ");
        sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, tmpMtmWfStepNotificationRule.getWorkflowStepID());
        setPrepareStatement(preStat, 2, tmpMtmWfStepNotificationRule.getNotifyTrigger());
        setPrepareStatement(preStat, 3, tmpMtmWfStepNotificationRule.getNotifyAtField());
        setPrepareStatement(preStat, 4, tmpMtmWfStepNotificationRule.getNotifyAtAmt());
        setPrepareStatement(preStat, 5, tmpMtmWfStepNotificationRule.getNotifyAckMethod());
        setPrepareStatement(preStat, 6, new Integer(tmpMtmWfStepNotificationRule.getUpdateCount().intValue() + 1));
        setPrepareStatement(preStat, 7, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 8, currTime);
        setPrepareStatement(preStat, 9, tmpMtmWfStepNotificationRule.getID());
        setPrepareStatement(preStat, 10, tmpMtmWfStepNotificationRule.getUpdateCount());
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        } else {
          tmpMtmWfStepNotificationRule.setUpdaterID(sessionContainer.getUserRecordID());
          tmpMtmWfStepNotificationRule.setUpdateDate(currTime);
          tmpMtmWfStepNotificationRule.setUpdateCount(new Integer(tmpMtmWfStepNotificationRule.getUpdateCount().intValue() + 1));
          tmpMtmWfStepNotificationRule.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWfStepNotificationRule.getCreatorID()));
          tmpMtmWfStepNotificationRule.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWfStepNotificationRule.getUpdaterID()));
          return(tmpMtmWfStepNotificationRule);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_UPDATE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected synchronized AbstractBaseObject delete(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    MtmWfStepNotificationRule tmpMtmWfStepNotificationRule = (MtmWfStepNotificationRule)((MtmWfStepNotificationRule)obj).clone();

    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        sqlStat.append("DELETE ");
        sqlStat.append("FROM   MTM_WF_STEP_NOTIFY_RULE ");
        sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, tmpMtmWfStepNotificationRule.getID());
        setPrepareStatement(preStat, 2, tmpMtmWfStepNotificationRule.getUpdateCount());
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        } else {
          return(tmpMtmWfStepNotificationRule);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  protected synchronized void auditTrail(String opMode, AbstractBaseObject obj) throws ApplicationException {
    Vector oldValues = new Vector();
    Vector newValues = new Vector();
    MtmWfStepNotificationRule tmpMtmWfStepNotificationRule = (MtmWfStepNotificationRule)this.oldValue;

    if (tmpMtmWfStepNotificationRule != null) {
      oldValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getID()));
      oldValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getWorkflowStepID()));
      oldValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getNotifyTrigger()));
      oldValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getNotifyAtField()));
      oldValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getNotifyAtAmt()));
      oldValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getNotifyAckMethod()));
      oldValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getRecordStatus()));
      oldValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getUpdateCount()));
      oldValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getCreatorID()));
      oldValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getCreateDate()));
      oldValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getUpdaterID()));
      oldValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getUpdateDate()));
    }

    tmpMtmWfStepNotificationRule = (MtmWfStepNotificationRule)obj;
    if (tmpMtmWfStepNotificationRule != null) {
      newValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getID()));
      newValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getWorkflowStepID()));
      newValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getNotifyTrigger()));
      newValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getNotifyAtField()));
      newValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getNotifyAtAmt()));
      newValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getNotifyAckMethod()));
      newValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getRecordStatus()));
      newValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getUpdateCount()));
      newValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getCreatorID()));
      newValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getCreateDate()));
      newValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getUpdaterID()));
      newValues.add(toAuditTrailValue(tmpMtmWfStepNotificationRule.getUpdateDate()));
    }

    auditTrailBase(opMode, oldValues, newValues);
  }
  /***********************************************************************
   * DON'T Modify the codes above unless you know what you are doing!!!  *
   * Put your own functions beblow.                                      *
   * For FINDER methods, the function name should be in the notation:    *
   *   public Object getObjectBy<Criteria>()                             *
   *   - e.g. public Object getObjectByCode()                            *
   *   public List getListBy<Criteria>()                                 *
   *   - e.g. public List getListByUserID()                              *
   * For OPERATION methods, the function name should be in the notation: *
   *   public void <Operation>ObjectBy<Criteria>()                       *
   *   - e.g. public void deleteObjectByCode()                           *
   *   public void <Operation>ListBy<Criteria>()                         *
   *   - e.g. public void deleteListByUserID()                           *
   ***********************************************************************/

  /**
   * Gets a list of notification rules created for the given workflow step
   * 
   * @param workflowStepID The workflow step ID
   * @return List of MtmWfStepNotificationRule objects
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowStep
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule 
   */
  public synchronized List getListByWorkflowStepID(Integer workflowStepID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.WORKFLOW_STEP_ID, A.NOTIFY_TRIGGER, A.NOTIFY_AT_FIELD, A.NOTIFY_AT_AMT, A.NOTIFY_ACK_METHOD, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   MTM_WF_STEP_NOTIFY_RULE A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? AND A.WORKFLOW_STEP_ID = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        this.setPrepareStatement(preStat, 2, workflowStepID);
        rs = preStat.executeQuery();
        while (rs.next()) {
          MtmWfStepNotificationRule tmpMtmWfStepNotificationRule = new MtmWfStepNotificationRule();
          tmpMtmWfStepNotificationRule.setID(getResultSetInteger(rs, "ID"));
          tmpMtmWfStepNotificationRule.setWorkflowStepID(getResultSetInteger(rs, "WORKFLOW_STEP_ID"));
          tmpMtmWfStepNotificationRule.setNotifyTrigger(getResultSetString(rs, "NOTIFY_TRIGGER"));
          tmpMtmWfStepNotificationRule.setNotifyAtField(getResultSetInteger(rs, "NOTIFY_AT_FIELD"));
          tmpMtmWfStepNotificationRule.setNotifyAtAmt(getResultSetInteger(rs, "NOTIFY_AT_AMT"));
          tmpMtmWfStepNotificationRule.setNotifyAckMethod(getResultSetString(rs, "NOTIFY_ACK_METHOD"));
          tmpMtmWfStepNotificationRule.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpMtmWfStepNotificationRule.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpMtmWfStepNotificationRule.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpMtmWfStepNotificationRule.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpMtmWfStepNotificationRule.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpMtmWfStepNotificationRule.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpMtmWfStepNotificationRule.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWfStepNotificationRule.getCreatorID()));
          tmpMtmWfStepNotificationRule.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWfStepNotificationRule.getUpdaterID()));
          result.add(tmpMtmWfStepNotificationRule);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  /**
   * Gets a list of notification rules with the specified trigger type 
   * created for the given workflow step 
   * 
   * @param workflowStepID The workflow step ID
   * @param notifyTrigger The trigger type
   * @return List of MtmWfStepNotificationRule objects
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowStep
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule#NOTIFY_TRIGGER_TYPE_ARRIVED 
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule#NOTIFY_TRIGGER_TYPE_BEFORE_DUE_DATE
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule#NOTIFY_TRIGGER_TYPE_CHECK_OUT_BY_USER
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule#NOTIFY_TRIGGER_TYPE_COMPLETED
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule#NOTIFY_TRIGGER_TYPE_COMPLETED_BY_USER
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule#NOTIFY_TRIGGER_TYPE_OVER_DUE_DATE
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule#NOTIFY_TRIGGER_TYPE_PENDING_FOR
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule#NOTIFY_TRIGGER_TYPE_PRIORITY_CHANGED
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule#NOTIFY_TRIGGER_TYPE_STOPPED
   */
  public synchronized List getListByWorkflowStepIDAndNotifyTrigger(Integer workflowStepID, List notifyTrigger) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();
    String tigger="";
    
    for (Iterator iter = notifyTrigger.iterator(); iter.hasNext();) {
      String element = (String) iter.next();
      if ("".equals(tigger)) {
        tigger="'"+element+"'";
      } else {
          tigger=tigger+","+"'"+element+"'";
      }
    }
    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.WORKFLOW_STEP_ID, A.NOTIFY_TRIGGER, A.NOTIFY_AT_FIELD, A.NOTIFY_AT_AMT, A.NOTIFY_ACK_METHOD, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   MTM_WF_STEP_NOTIFY_RULE A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? AND A.WORKFLOW_STEP_ID = ? AND A.NOTIFY_TRIGGER in ("+tigger+")");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        this.setPrepareStatement(preStat, 2, workflowStepID);
        rs = preStat.executeQuery();
        while (rs.next()) {
          MtmWfStepNotificationRule tmpMtmWfStepNotificationRule = new MtmWfStepNotificationRule();
          tmpMtmWfStepNotificationRule.setID(getResultSetInteger(rs, "ID"));
          tmpMtmWfStepNotificationRule.setWorkflowStepID(getResultSetInteger(rs, "WORKFLOW_STEP_ID"));
          tmpMtmWfStepNotificationRule.setNotifyTrigger(getResultSetString(rs, "NOTIFY_TRIGGER"));
          tmpMtmWfStepNotificationRule.setNotifyAtField(getResultSetInteger(rs, "NOTIFY_AT_FIELD"));
          tmpMtmWfStepNotificationRule.setNotifyAtAmt(getResultSetInteger(rs, "NOTIFY_AT_AMT"));
          tmpMtmWfStepNotificationRule.setNotifyAckMethod(getResultSetString(rs, "NOTIFY_ACK_METHOD"));
          tmpMtmWfStepNotificationRule.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpMtmWfStepNotificationRule.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpMtmWfStepNotificationRule.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpMtmWfStepNotificationRule.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpMtmWfStepNotificationRule.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpMtmWfStepNotificationRule.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpMtmWfStepNotificationRule.setCreatorName(UserInfoFactory.getUserFullName(tmpMtmWfStepNotificationRule.getCreatorID()));
          tmpMtmWfStepNotificationRule.setUpdaterName(UserInfoFactory.getUserFullName(tmpMtmWfStepNotificationRule.getUpdaterID()));
          result.add(tmpMtmWfStepNotificationRule);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  /**
   * Gets a list of notification rules with the specified trigger type 
   * created for the given workflow step 
   * 
   * @param workflowStepID The workflow step ID
   * @param notifyTrigger The trigger type
   * @return List of MtmWfStepNotificationRule objects
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowStep
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule#NOTIFY_TRIGGER_TYPE_ARRIVED 
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule#NOTIFY_TRIGGER_TYPE_BEFORE_DUE_DATE
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule#NOTIFY_TRIGGER_TYPE_CHECK_OUT_BY_USER
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule#NOTIFY_TRIGGER_TYPE_COMPLETED
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule#NOTIFY_TRIGGER_TYPE_COMPLETED_BY_USER
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule#NOTIFY_TRIGGER_TYPE_OVER_DUE_DATE
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule#NOTIFY_TRIGGER_TYPE_PENDING_FOR
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule#NOTIFY_TRIGGER_TYPE_PRIORITY_CHANGED
   * @see com.dcivision.workflow.bean.MtmWfStepNotificationRule#NOTIFY_TRIGGER_TYPE_STOPPED
   */
  public synchronized List getListByWorkflowStepIDAndNotifyTrigger(Integer workflowStepID, String notifyTrigger) throws ApplicationException {
    List list = new ArrayList();
    if ((notifyTrigger != null) && (!notifyTrigger.equals("")))
      list.add(notifyTrigger);
    return getListByWorkflowStepIDAndNotifyTrigger(workflowStepID, list);
  }
  /**
   * Deletes all the notification rules of the given workflow step
   * 
   * @param workflowStepID The workflow step ID
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowStep
   */
  public synchronized void deleteNotifyRuleByWorkflowStepID(Integer workflowStepID) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();

    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        sqlStat.append("DELETE ");
        sqlStat.append("FROM   MTM_WF_STEP_NOTIFY_RULE ");
        sqlStat.append("WHERE  WORKFLOW_STEP_ID = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, workflowStepID);
        updateCnt = preStat.executeUpdate();
        
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  public String[][] getNotifyTaskTypeByStepType(String setpActionType) {
    /*
     * String TRIGGER_TYPE_MAP[][] = { {"workflow.label.notify_task_is_arrived", MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_ARRIVED},
     * {"workflow.label.notify_task_is_pending", MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_PENDING_FOR}, {"workflow.label.notify_task_priority_changed",
     * MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_PRIORITY_CHANGED}, {"workflow.label.notify_task_is_check_out_by_user",
     * MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_CHECK_OUT_BY_USER}, {"workflow.label.notify_task_is_completed_by_user",
     * MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_COMPLETED_BY_USER}, {"workflow.label.notify_task_is_completed",
     * MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_COMPLETED}, {"workflow.label.notify_task_is_stoped",
     * MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_STOPPED}, {"workflow.label.before_task_due_date",
     * MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_BEFORE_DUE_DATE}, {"workflow.label.notify_task_is_overdue",
     * MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_OVER_DUE_DATE} };
     */

    String tiggerType[][] = null;
    int branchCount = 0;
    if (WorkflowStep.ACTION_TYPE_APPROVAL.equals(setpActionType)) {
      tiggerType = new String[11][2];
      setStandNotifyType(tiggerType);

      tiggerType[9][0] = "workflow.label.notify_task_is_approved";
      tiggerType[9][1] = MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_APPROVED;
      tiggerType[10][0] = "workflow.label.notify_task_is_reject";
      tiggerType[10][1] = MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_REJECT;

    } else if (WorkflowStep.ACTION_TYPE_BOOLEAN.equals(setpActionType)) {
      tiggerType = new String[11][2];
      setStandNotifyType(tiggerType);
      
      tiggerType[9][0] = "workflow.label.notify_task_is_yes";
      tiggerType[9][1] = MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_YES;
      tiggerType[10][0] = "workflow.label.notify_task_is_no";
      tiggerType[10][1] = MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_NO;

    } else if ( !Utility.isEmpty( setpActionType) &&  setpActionType.length()>1) {
      String[] routeArr = TextUtility.splitString(setpActionType,"|");
      if  (Utility.isEmpty(routeArr)){
        tiggerType = new String[9][2];
        setStandNotifyType(tiggerType);
      }
      else{
        tiggerType = new String[9+routeArr.length ][2];
        setStandNotifyType(tiggerType);
        
        for (int i = 0; i < routeArr.length; i++) {
          tiggerType[9+i][0] = "workflow.label.notify_task_is_decision";
          tiggerType[9+i][1] = MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_DECISION+i;
        }
        
      }
//      tiggerType = new String[branchCount + 9][2];
//      setStandNotifyType(tiggerType);
      
    } else {
      tiggerType = new String[9][2];
      setStandNotifyType(tiggerType);
    }

    return tiggerType;
  }

  private void setStandNotifyType(String[][] tiggerType) {
    tiggerType[0]=new String[] {"workflow.label.notify_task_is_arrived", MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_ARRIVED};
    tiggerType[1]=new String[]{"workflow.label.notify_task_is_pending", MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_PENDING_FOR};
    tiggerType[2]=new String[] {"workflow.label.notify_task_priority_changed", MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_PRIORITY_CHANGED};
    tiggerType[3]=new String[]{"workflow.label.notify_task_is_Picked_Up_by_user", MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_CHECK_OUT_BY_USER};
    tiggerType[4]=new String[]{"workflow.label.notify_task_is_completed_by_user", MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_COMPLETED_BY_USER};
    tiggerType[5]=new String[]{"workflow.label.notify_task_is_completed", MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_COMPLETED};
    tiggerType[6]=new String[]{"workflow.label.notify_task_is_stoped", MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_STOPPED};
    tiggerType[7]=new String[]{"workflow.label.before_task_due_date", MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_BEFORE_DUE_DATE};
    tiggerType[8]=new String[]{"workflow.label.notify_task_is_overdue", MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_OVER_DUE_DATE};
  }

  public void deleteNotifyRuleForSpecialActorByWorkflowStepID(Integer workflowStepID) throws ApplicationException {
    String condition = " TARGET_ID = " + workflowStepID + 
    " AND (TARGET_TYPE = '"+MtmWfStepNotificationTarget.TARGET_TYPE_ACTION_TAKER+"'"+
    " OR TARGET_TYPE = '"+MtmWfStepNotificationTarget.TARGET_TYPE_OWNER+"')";
    
    //Integer notifyRuleID = SqlAccountUtility.getIntegerFieldValueFromFieldName(dbConn, "MTM_WF_STEP_NOTIFY_TARGET",
    //    "NOTIFY_RULE_ID", condition);
    List list=SqlAccountUtility.getIntegerListFieldValueFromFieldName(dbConn, "MTM_WF_STEP_NOTIFY_TARGET",
        "NOTIFY_RULE_ID", condition);
    // if no notify contact the step then exit
    if (list == null) {
      return;
    }    
    SqlAccountUtility.deleteRecordFromSql(dbConn, "MTM_WF_STEP_NOTIFY_TARGET", condition);
    Iterator it=list.iterator();
    while(it.hasNext()){
    Integer id=(Integer)it.next();
    condition = " NOTIFY_RULE_ID = " + id.toString();
    int ruleNotifyTargetCount = SqlAccountUtility.getIDCountFromSql(dbConn, "MTM_WF_STEP_NOTIFY_TARGET", condition);

    // when the notify rule no target ,then delete notifyRule
    if (ruleNotifyTargetCount == 0) {
      condition = " ID=" + id.toString();
      SqlAccountUtility.deleteRecordFromSql(dbConn, "MTM_WF_STEP_NOTIFY_RULE", condition);
    }
    }
  }
}
